import React, {Component} from 'react';
import {Link} from 'umi';
import {Layout, Menu} from 'antd';
import styles from './Nav.less';

const {Header} = Layout;
import {connect} from 'dva';

const SubMenu = Menu.SubMenu;

@connect(({nav}) => ({
  nav,
}))
class Nav extends Component {
  state = {
    defaultSelectedKeys: []
  }

  componentWillMount() {
    // const {routes, location} = this.props
    // const menuTreeNode = this.renderMenu(routes.routes, location.pathname);
    // this.setState({
    //   menuTreeNode
    // })
  }

  // 递归实现----菜单渲染
  renderMenu = (data, pathname) => {
    return data.map((item) => {
        if (item.hide !== true) {
          if (item.children) {
            return <SubMenu key={item.path} title={item.name}>
              {this.renderMenu(item.children)}
            </SubMenu>
          }
          return <Menu.Item key={item.path} title={item.name}><Link to={item.path}>{item.name}</Link></Menu.Item>
        }
      }
    )
  }


  render() {
    const {nav: {selectedNavs}} = this.props
    return (
      <Header className={styles.fixedHeader ? styles.fixedHeader : ''}>
        <div className={styles.logo}>SameReport</div>
        {/*<Menu theme="light" mode="horizontal" selectedKeys={selectedNavs}>*/}
        {/*  {this.state.menuTreeNode}*/}
        {/*</Menu>*/}
      </Header>
    );
  }
}

export default Nav
